package com.gcsj.gcsjspringboot.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gcsj.gcsjspringboot.entity.SysRoleEntity;
import com.gcsj.gcsjspringboot.entity.SysUserRoleEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户与角色对应关系
 *
 * @author
 */
@Mapper
public interface SysUserRoleDao extends BaseMapper<SysUserRoleEntity> {

	/**
	 * 根据用户ID，获取角色ID列表
	 */
	@Select("select role_id from sys_user_role where user_id = #{userId}")
	List<Long> queryRoleIdList(Long userId);
	@Select("select a.role_id, role_name from sys_user_role a,sys_role b where a.role_id = b.role_id and a.user_id = #{userId}")
	List<SysRoleEntity> queryRoleList(Long userId);
	@Select("select * from sys_user_role a, sys_role b \n" +
			"where a.role_id = b.role_id and a.user_id = #{userId}")
	List<SysRoleEntity> getRolesByUser(Long userId);

	/**
	 * 根据角色ID数组，批量删除
	 */
	int deleteBatch(Long[] roleIds);
}
